﻿<Controls:WindowEx x:Class="BillsManager.Views.ViewWindow"
                   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                   xmlns:Controls="clr-namespace:BillsManager.Views.Controls"
                   xmlns:Shell="http://schemas.microsoft.com/netfx/2009/xaml/presentation"
                   xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                   xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                   MinWidth="250"
                   MinHeight="48"
                   FontFamily="Segoe UI"
                   Icon="Images/Product-documentation32.png"
                   SizeToContent="WidthAndHeight"
                   TextOptions.TextFormattingMode="Ideal"
                   TextOptions.TextHintingMode="Fixed"
                   TextOptions.TextRenderingMode="Auto"
                   d:DesignHeight="320"
                   d:DesignWidth="600"
                   mc:Ignorable="d">

    <Controls:WindowEx.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <!--<ResourceDictionary Source="Dictionaries\Styles.xaml" />-->
                <ResourceDictionary Source="Themes\Themes.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <Style x:Key="ViewWindowStyle" TargetType="{x:Type Controls:WindowEx}">

                <Setter Property="UseLayoutRounding" Value="True" />
                <!--
                    <Setter Property="AllowsTransparency"
                    Value="True" />
                -->
                <!--
                    <Setter Property="WindowStyle"
                    Value="None" />
                -->

                <Setter Property="Background" Value="{StaticResource View.Background}" />
                <Setter Property="BorderBrush" Value="{StaticResource View.BorderBrush}" />
                <Setter Property="Foreground" Value="{StaticResource View.Foreground.Normal}" />
                <Setter Property="FontSize" Value="{StaticResource View.FontSize}" />

                <Setter Property="MinHeight" Value="38" />

                <Setter Property="Shell:WindowChrome.WindowChrome">
                    <Setter.Value>
                        <Shell:WindowChrome CaptionHeight="32"
                                            CornerRadius="{StaticResource ViewWindow.Border.CornerRadius}"
                                            GlassFrameThickness="0"
                                            NonClientFrameEdges="None"
                                            ResizeBorderThickness="{StaticResource ViewWindow.ResizeBorder.Thickness}" />
                    </Setter.Value>
                </Setter>

                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Controls:WindowEx}">

                            <AdornerDecorator>

                                <Border x:Name="WindowBorder"
                                        Background="{StaticResource View.Background}"
                                        BorderBrush="{StaticResource View.BorderBrush}"
                                        BorderThickness="{StaticResource View.Border.Thickness}"
                                        Padding="{StaticResource View.Border.Padding.Normal}">

                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition />
                                        </Grid.RowDefinitions>

                                        <Grid x:Name="CaptionBar" HorizontalAlignment="Stretch">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="{StaticResource View.MarginSize}" />
                                                <ColumnDefinition />
                                                <ColumnDefinition Width="{StaticResource View.MarginSize}" />
                                                <ColumnDefinition Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <Grid.RowDefinitions>
                                                <RowDefinition />
                                                <RowDefinition Height="{StaticResource View.Region.Spacing.Normal}" />
                                            </Grid.RowDefinitions>

                                            <!--
                                                <TextBlock Background="Green"
                                                Grid.ColumnSpan="5"
                                                TextAlignment="Center"
                                                Foreground="White"
                                                Text="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}" />
                                            -->

                                            <Image Width="{StaticResource View.Icon.Size}"
                                                   Height="{StaticResource View.Icon.Size}"
                                                   HorizontalAlignment="Left"
                                                   VerticalAlignment="Top"
                                                   Source="{TemplateBinding Icon}"
                                                   Stretch="Uniform">
                                                <Image.Margin>
                                                    <Thickness Bottom="{StaticResource View.Region.Spacing.SmallValue}"
                                                               Left="{StaticResource View.Region.Spacing.SmallValue}"
                                                               Right="{StaticResource View.Region.Spacing.SmallValue}"
                                                               Top="{StaticResource View.Region.Spacing.SmallValue}" />
                                                </Image.Margin>
                                            </Image>

                                            <TextBlock Grid.Column="2"
                                                       HorizontalAlignment="Stretch"
                                                       VerticalAlignment="Center"
                                                       FontSize="{StaticResource View.Title.FontSize}"
                                                       FontWeight="{StaticResource View.Title.FontWeight}"
                                                       Foreground="{StaticResource View.Title.Foreground}"
                                                       Text="{TemplateBinding Title}"
                                                       TextAlignment="Center"
                                                       TextTrimming="CharacterEllipsis"
                                                       TextWrapping="NoWrap" />

                                            <StackPanel x:Name="controlBox"
                                                        Grid.Column="4"
                                                        HorizontalAlignment="Right"
                                                        VerticalAlignment="Top"
                                                        Orientation="Horizontal"
                                                        Shell:WindowChrome.IsHitTestVisibleInChrome="True">
                                                <Controls:MinimizeWindowButton Visibility="{Binding ShowInTaskbar, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource TemplatedParent}}" />
                                                <Controls:NormalizeWindowButton x:Name="NormalizeWindowButton" Visibility="Collapsed" />
                                                <Controls:MaximizeWindowButton x:Name="MaximizeWindowButton" />
                                                <Controls:CloseWindowButton Visibility="{Binding CanClose, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource TemplatedParent}}" />
                                            </StackPanel>

                                        </Grid>

                                        <ContentPresenter Grid.Row="2"
                                                          Content="{TemplateBinding Content}"
                                                          ContentStringFormat="{TemplateBinding ContentStringFormat}"
                                                          ContentTemplate="{TemplateBinding ContentTemplate}" />

                                    </Grid>

                                </Border>

                            </AdornerDecorator>

                            <ControlTemplate.Triggers>

                                <Trigger Property="WindowState" Value="Maximized">
                                    <Setter TargetName="WindowBorder" Property="Padding" Value="{StaticResource View.Border.Padding.Maximized}" />
                                    <Setter TargetName="NormalizeWindowButton" Property="Visibility" Value="Visible" />
                                    <Setter TargetName="MaximizeWindowButton" Property="Visibility" Value="Collapsed" />
                                    <!--
                                        <Setter TargetName="controlBox"
                                        Property="Margin"
                                        Value="0 -1 -1 0" />
                                    -->
                                </Trigger>

                                <Trigger Property="ResizeMode" Value="NoResize">
                                    <Setter TargetName="NormalizeWindowButton" Property="Visibility" Value="Collapsed" />
                                    <Setter TargetName="MaximizeWindowButton" Property="Visibility" Value="Collapsed" />
                                </Trigger>

                            </ControlTemplate.Triggers>

                        </ControlTemplate>
                    </Setter.Value>
                </Setter>

            </Style>

        </ResourceDictionary>
    </Controls:WindowEx.Resources>

    <Controls:WindowEx.Style>
        <Binding Mode="OneTime" Source="{StaticResource ViewWindowStyle}" />
    </Controls:WindowEx.Style>

</Controls:WindowEx>